package logic

import (
	"context"
	"errors"
	"srv/models/mysqlinit"

	"srv/internal/svc"
	"srv/srv"

	"github.com/zeromicro/go-zero/core/logx"
)

type AdmHouseStatusLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAdmHouseStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdmHouseStatusLogic {
	return &AdmHouseStatusLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AdmHouseStatusLogic) AdmHouseStatus(in *srv.AdmHouseStatusRequest) (*srv.AdmHouseStatusResponse, error) {
	// todo: add your logic here and delete this line
	h := mysqlinit.House{}
	h.HouseStatus = int(in.HouseStatus)
	err := h.UpdateHouseStatus(in.HouseId, in.GetHouseStatus())
	if err != nil {
		logx.Error("房源审核失败")
		return nil, errors.New("房源审核失败")
	}
	return &srv.AdmHouseStatusResponse{
		Type: true,
	}, nil
}
